package com.daocao.common.service.impl;

import java.time.LocalDateTime;
import java.util.Arrays;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daocao.common.domain.dto.UmsDetailResumeDto;
import com.daocao.common.domain.entity.UmsDetailResume;
import com.daocao.common.mapper.UmsDetailResumeMapper;
import com.daocao.common.response.DaoCaoPageResult;
import com.daocao.common.service.IUmsDetailResumeService;
import com.daocao.common.utils.security.DaoCaoSecurityUtil;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class UmsDetailResumeServiceImpl extends ServiceImpl<UmsDetailResumeMapper, UmsDetailResume> implements IUmsDetailResumeService{


    @Override
    public DaoCaoPageResult<UmsDetailResume> searchList(UmsDetailResumeDto detailResumeDto) {
        // 获取用户id
        Long userId = DaoCaoSecurityUtil.getUserId();

        LambdaQueryWrapper<UmsDetailResume> wrapper = new LambdaQueryWrapper<>();
        log.info("InsertTime=====>"+detailResumeDto.getInsertTime());
        // 搜索条件
        if (StrUtil.isNotEmpty(detailResumeDto.getInsertTime())) {
            //模糊查询
            wrapper.likeRight(UmsDetailResume::getInsertTime, detailResumeDto.getInsertTime())
                   .eq(UmsDetailResume::getId, userId);
        } else {
            //模糊查询
            wrapper.eq(UmsDetailResume::getId, userId);
        }
        // 创建分页对象
        //IPage<UmsDetailResume> page; // 参数1：当前页，参数2：每页显示条数，根据需要调整
        // 执行分页查询
        DaoCaoPageResult<UmsDetailResume> resultPage = baseMapper.selectPage(detailResumeDto, wrapper);
        // 返回分页结果
        return resultPage;
    }

    @Override
    public int insertDetailResume(UmsDetailResume umsDetailResume) {
        String creator = DaoCaoSecurityUtil.getUsername();
        umsDetailResume.setCreator(creator);
        umsDetailResume.setInsertTime(LocalDateTime.now());

        return baseMapper.insert(umsDetailResume);
    }

    @Override
    public int removeResume(String[] insertTimes) {

        return baseMapper.deleteBatchIds(Arrays.asList(insertTimes));
    }
    


    
}
